<extend name="Public:iframe" />
<block name="content">
    <form class="layui-form" action="">
        <table class="layui-table">
            <colgroup>
                <col width="150">
                <col width="200">
                <col width="400">
            </colgroup>
            <tr>
                <th>一级目录</th>
                <th>二级目录</th>
                <th>内部操作</th>
            </tr>

            <volist name="menu" id="m">
                <assign name="var" value="1" />
                <volist name="menu_child" id="c" key="k">
                    <if condition="$c['pid'] eq $m['id']">
                        <tr>
                            <td >
                                <if condition="$var eq 1">
                                <input type="checkbox" name="menu[{$m.id}]" title="{$m.name}"
                                   <foreach name="info['menu_ids']" item="ids">
                                        <if  condition='$m.id eq $ids'> checked </if>
                                    </foreach>
                                >
                                </if>
                                <input type="hidden" value="{$var++}">
                            </td>
                            <td>
                                <input type="checkbox" name="child[{$c.id}]" title="{$c.name}"
                                    <foreach name="info['menu_ids']" item="ids">
                                        <if  condition='$c.id eq $ids'> checked </if>
                                    </foreach>
                                >
                            </td>
                            <td>
                                <volist name="auth" id="a">
                                    <if condition="$a.mid eq $c.id or $a.pid eq $m.id">
                                        <input type="checkbox" name="auth[{$a.id}]" title="{$a.name}"
                                            <foreach name="info['auth_ids']" item="ids">
                                                <if  condition='$a.id eq $ids'> checked </if>
                                            </foreach>
                                        >
                                    </if>
                                </volist>
                            </td>
                        </tr>
                    </if>
                </volist>
            </volist>
        </table>
    </form>
</block>

<block name="foot_script">
    <script>
        $(layui.use(['layer','form','upload'], function(){
            var layer = layui.layer,form = layui.form,upload = layui.upload;


            form.on('submit(submit)',function (data) {
                $.post('{:U("User/edit")}',data.field,function (res) {
                    if (res.code === 1){
                        layer.msg(res.msg,{time:1000},function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            window.location.reload();
                        });
                    } else {
                        layer.msg(res.msg,{time:1000});
                    }
                });
                return false;
            });

        }));
        var id = {$info.id};
        $('.layui-form-checkbox').click(function(){
            var type = $(this).prev('input').attr('name');
            var status = $(this).prev('input').prop('checked');
            $.ajax({
                type:'POST',
                url:"{:U('Adminrole/changeRole')}",
                data:{'id':id,'type':type,'status':status},
                success:function(res){
                    if(res.code==1)
                    {
                        layer.msg(res.msg,{'time':1000});
                        window.location.reload();
                    }else{
                        layer.msg(res.msg);
                    }
                }
            });
        });

        $('#refresh').click(function(){
            window.location.reload();
        });
    </script>
</block>